<html>
<head>
<?php echo $this->headLink()->prependStylesheet($this->baseUrl().'/res/details.css'); ?>
<script type='text/javascript'>
function enableEdit(){
	if(document.getElementById('ipField').disabled==false){
		setTimeout("location.reload(true);",0)
	}
	document.getElementById('ipField').disabled=false;
	document.getElementById('locationField').disabled=false;
	document.getElementById('updatedField').disabled=false;
	document.getElementById('commentsField').disabled=false;
	document.getElementById('save').disabled=false;
	document.getElementById('contacts').disabled=false;
	document.getElementById('serialField').disabled=false;
	document.getElementById('edit').value="Cancel";
}
</script>
<?php
	$user=new Zend_Session_Namespace('user');
	$loggedIn=($user->username != "");
	$contactNamespace=new Zend_Session_Namespace('contacts');
	$contacts=$contactNamespace->contacts;
?>
</head>
<body>
<div id="container">
<?php
	$detailNamespace = new Zend_Session_Namespace('details');
	$details=$detailNamespace->results;
	$search = new Zend_Session_Namespace('search');
	//echo(print_r($contacts));
	if ($search->back_to_results)
		echo("<h3><a href='/index/return'>Back to Results</a></h2>");
	
	echo("<h2>Component Info:");
	if($loggedIn){
	echo("<input type='submit' id='edit' name='edit' value='Edit' onClick='enableEdit()'/>");
	}
	echo("</h2>");
	echo("<form method='POST' action='/index/updatecomponent'>");
	echo("<input type='hidden' name='component_id' value='".$_GET['id']."'/>");
	echo("<table class='details'>");
	echo("<th>IP Address</th><th>Building</th><th>Location</th><th>Last Inspected</th><th>Comments</th><th>Serial Number</th>");
	echo("<tr>");
	if($loggedIn){
		echo("<td><input type='text' disabled='true' id='ipField' name='ip_address' value='".$details['info']['ip_address']."'/></td>");
		echo("<td>".$details['info']['building_name']."</td>");
		echo("<td><input type='text' disabled='true' id='locationField' name='location' value='".$details['info']['location']."'/></td>");
		echo("<td><input type='text' disabled='true' id='updatedField' name='last_inspected' value='".$details['info']['last_inspected']."'/></td>");
		//echo("<td><input type='text' disabled='true' id='commentsField' name='component_comments' value='".$details['info']['component_comments']."'/></td>");
		echo("<td><textarea disabled='true' id='commentsField' name='component_comments'>".$details['info']['component_comments']."</textarea></td>");
		echo("<td><input type='text' disabled='true' id='serialField' name='serial_number' value='".$details['info']['serial_number']."'/></td>");
		echo("</tr>");
		echo("</table><br/>");
	}
	else{
		echo("<td>".$details['info']['ip_address']."</td>");
		echo("<td>".$details['info']['building_name']."</td>");
		echo("<td>".$details['info']['location']."</td>");
		echo("<td>".$details['info']['last_inspected']."</td>");
		echo("<td>".$details['info']['component_comments']."</td>");
		echo("<td>".$details['info']['serial_number']."</td>");
		echo("</tr>");
		echo("</table><br/>");
	}	

	echo("<table class='detailsMeta'>");
		if($loggedIn){echo("<tr><td><h2>Device Info:</h2></td><td><h2>SNMP:</h2></td><td><h2>Contact Info:");}
		else{echo("<tr><td><h2>Device Info:</h2></td><td><h2>Contact Info:");}

		if($loggedIn){
			echo("<select id='contacts' name='contact_id' disabled='true'>");
			foreach($contacts as $contact){
				if($contact['contact_id']==$details['info']['contact_id']){
					echo("<option selected='selected' value='".$contact['contact_id']."'>".$contact['contact_name']."</option>");
				}
				else{echo("<option value='".$contact['contact_id']."'>".$contact['contact_name']."</option>");}
			} 
			echo("</select>");
		}
		echo("</h2></td></tr>");
		
		echo("<tr><td>");
		echo("<table class='details'>");
		echo("<th>Manufacturer</th><th>Model</th>");
		echo("<tr>");
		echo("<td>".$details['info']['make_name']."</td>");
		echo("<td>".$details['info']['device_name']."</td>");
		echo("</tr>");
		echo("</table>");
		echo("</td><td>");
		if($loggedIn){
			echo("<table class='details'>");
			echo("<th>Profile Name:</th><th>Version</th><th>Readonly</th><th>Readwrite</th><th>User</th><th>Auth</th><th>Priv</th>");
			echo("<tr><td>".$details['info']['profile_name']."</td>");
			echo("<td>".$details['info']['version']."</td>");
			echo("<td>".$details['info']['readonly']."</td>");
			echo("<td>".$details['info']['readwrite']."</td>");
			echo("<td>".$details['info']['user']."</td>");
			echo("<td>".$details['info']['auth']."</td>");
			echo("<td>".$details['info']['priv']."</td>");
			echo("</table>");
			echo("</td><td>");
		}
		echo("<table class='details'>");
		echo("<th>Name</th><th>Phone Number</th><th>Email</th>");
		echo("<tr>");
		echo("<td>".$details['info']['contact_name']."</td>");
		echo("<td>".$details['info']['telephone']."</td>");
		echo("<td>".$details['info']['email']."</td>");
		echo("</tr>");
		echo("</table>");
		echo("</td>");
		echo("</tr>");
	echo("</table>");
	
	if($loggedIn){
		echo("<br /><input type='submit' id='save' name='save' value='Save' disabled='true'/><br /><br />");
	}

	echo("<table class='detailsMeta'><td>");
	echo("<h2>Port Usage:</h2>");
	echo("<table class='portUsage'>");
		echo("<tr>");
		if(count($details['portUsage']['to'])>0){
		echo("<td>");
		echo("<h3>To:</h3>");
		echo("<table class='details'>");
		echo("<th>IP Address</th><th>Port</th><th>Comments</th>");
		foreach($details['portUsage']['to'] as $row){			
			echo("<tr>");
			echo("<td><a href='/index/viewdetails?id=".$row['component_id']."'>".$row['ip_address']."</a></td>");
			echo("<td>".$row['port']."</td>");
			echo("<td>".$row['port_usage_comments']."</td>");
			echo("</tr>");
		}
		echo("</table>");
		echo("</td>");
		}
		
		if(count($details['portUsage']['from'])>0){
		echo("<td>");
		echo("<h3>From:</h3>");
		echo("<table class='details'>");
		echo("<th>IP Address</th><th>Port</th><th>Comments</th>");
		foreach($details['portUsage']['from'] as $row){			
			echo("<tr>");
			echo("<td><a href='/index/viewdetails?id=".$row['component_id']."'>".$row['ip_address']."</a></td>");
			echo("<td>".$row['destination_port']."</td>");
			echo("<td>".$row['port_usage_comments']."</td>");
			echo("</tr>");
		}
		echo("</table></td>");
		}

		if(count($details['portUsage']['services'])>0){
		echo("<td>");
		echo("<h3>Services:</h3>");
		echo("<table class='details'>");
		echo("<th>Port</th><th>Description</th>");
		foreach($details['portUsage']['services'] as $row){			
			echo("<tr>");
			echo("<td>".$row['port']."</td>");
			echo("<td>".$row['port_usage_comments']."</td>");
			echo("</tr>");
		}
		echo("</table></td>");		
		}
	echo("</table></td>");
	echo("</tr>");
	echo("</table>");
	echo("</form>");
?>
</div>
</body>
</html>
